
package org.soekrat.engine.socraton;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

public final class BisonService 
{
  private final String m_url="http://ahaxproject.appspot.com/bisons";
  
  public BisonService(){}
  
  /**
   * <p>
   * </p>
   * @param ref
   * @param format
   * @param data
   * @return
   * @throws IOException
   */
  public String data(boolean ref, String format, String data) throws IOException
  {
    URL url=new URL(m_url);    
    URLConnection con=url.openConnection();
    con.setDoOutput(true);

    OutputStream os=con.getOutputStream();
    DataOutputStream dos=new DataOutputStream(os);
    
    dos.writeUTF("data");
    
    dos.writeBoolean(ref);
    dos.writeUTF(format);
    byte[] bdata=data.getBytes();
    os.write(bdata);
    
    InputStream is=con.getInputStream();
    BufferedReader br=new BufferedReader(new InputStreamReader(is));
    String line=br.readLine();
    return line;
  }
  
}
